問題の説明
Selenium‑vba クラス名で要素を取得 (Selenium‑vba Get element by Class Name)
次のことをしようとすると、「オブジェクトはプロパティまたはメソッドをサポートしていません」というエラーが表示されます
Sub Testing()
Dim driver As New SeleniumWrapper.WebDriver
driver.Start "chrome", "http://www.tsn.ca/fury‑upsets‑klitschko‑to‑become‑heavyweight‑champion‑1.401257"
driver.Open "/"
MsgBox driver.getElementsByClassName("headline").Text
End Sub
driver.getElementsByClassName("headline")(0).Text<も試しました/コード>
リファレンスソリューション
方法 1:
It is not "get" ‑ it is "find":
driver.findElementByClassName("headline").Text
Alternatively, using a CSS selector:
driver.findElementByCssSelector(".headline").Text
方法 2:
The headline element within the website is:
<div class="headline">
<h1>Fury upsets Klitschko to win heavyweight titles</h1>
</div>
So you can use either of the following Locator Strategies:
Using FindElementByClassName:
driver.FindElementByClassName("headline").Text
Using FindElementByCss:
driver.FindElementByCss("div.headline > h1").Text
Using FindElementByXPath:
driver.FindElementByXPath("//div[@class='headline']/h1").Text
(by Display name、alecxe、undetected Selenium)
リファレンスドキュメント